package com.wbp.cms.core.eventbus;

import java.util.EventListener;
import java.util.EventObject;
import java.util.Set;
import java.util.concurrent.Executor;

import org.apache.log4j.Logger;

import com.google.common.eventbus.AsyncEventBus;


/**
 * 在 beans-event.xml中初始化
 * 
 * @Description: 预约项目流程状态事件发布者
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午3:00:41
 */
public class ProjectAsynEventBus extends AsyncEventBus {

  private static final Logger logger = Logger.getLogger(ProjectAsynEventBus.class);


  /**
   * @param executor
   */
  public ProjectAsynEventBus(Executor executor) {
    super(executor);
  }

  public synchronized void setEventListeners(Set<EventListener> eventListeners) {
    if (eventListeners != null) {
      for (EventListener listener : eventListeners) {
        register(listener);
      }
    }
  }

  @Override
  public void post(Object event) {
    if (!(event instanceof EventObject)) {
      logger.error("eventObject 要是EventObject的子类,event:" + event);
      return;
    }

    try {
      super.post(event);
    } catch (Exception e) {
      logger.error("AsyncEventBus pos fail.", e);
    }

  }


}
